package com.deng.springboot.demo.web.config;

import com.alibaba.druid.support.spring.stat.DruidStatInterceptor;
import org.springframework.aop.Advisor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.JdkRegexpMethodPointcut;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

/**
 * @author 邓力宾
 * @date 2020/3/1111:18
 * @Description: druid 监控spring 方法 需要启用aop功能
 */
@SpringBootConfiguration
public class DruidSpringMethodMonitorConfig {

    //Spring 方法监控
    @Bean
    public DruidStatInterceptor druidStatInterceptor(){
        return new DruidStatInterceptor();
    }
    //切入点
    @Bean
    public JdkRegexpMethodPointcut jdkRegexpMethodPointcut(){
        JdkRegexpMethodPointcut jdkRegexpMethodPointcut = new JdkRegexpMethodPointcut();
        jdkRegexpMethodPointcut.setPattern("com.deng.springboot.demo.web.service.*");
        return jdkRegexpMethodPointcut;
    }
    @Bean
    public Advisor druidAdvisor(DruidStatInterceptor druidStatInterceptor, JdkRegexpMethodPointcut druidStatPointcut) {
        DefaultPointcutAdvisor defaultPointcutAdvisor
                = new DefaultPointcutAdvisor();
        defaultPointcutAdvisor.setPointcut(druidStatPointcut);
        defaultPointcutAdvisor.setAdvice(druidStatInterceptor);
        return defaultPointcutAdvisor;
    }
}
